home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume9 / rndname3 < prev    next >
Encoding:
Text File  |  1989-11-08  |  10.9 KB  |  330 lines

  1. Newsgroups: comp.sources.misc
  2. subject: v09i002: rndname3: Random Name Generator for RPGs, Version 3.0
  3. From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  4. Reply-To: slocum@hi-csc.UUCP
  5.  
  6. Posting-number: Volume 9, Issue 2
  7. Submitted-by: slocum@hi-csc.UUCP
  8. Archive-name: rndname3
  9.  
  10. This is version 3.0 of my rndname program. The major addition
  11. to this program is the inclusion of the Scrabble (tm) letter
  12. distribution, as well as the previous flat distribution.
  13. By adding the -DSCRABBLE switch in the Makefile, the program
  14. is generated with these distributions.
  15.  
  16. Please send me any comments or modifications you have.
  17. ---
  18. Brett Slocum, Honeywell SSDC, Golden Valley, Minnesota
  19. <uunet!hi-csc!slocum>              | AIDS is a virus; George Bush
  20.   or <hi-csc!slocum@uunet.uu.net>  | is a punishment from God.
  21.  
  22. #! /bin/sh
  23. # This is a shell archive.  Remove anything before this line, then unpack
  24. # it by saving it into a file and typing "sh file".  To overwrite existing
  25. # files, type "sh file -c".  You can also feed this as standard input via
  26. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  27. # will see the following message at the end:
  28. #        "End of archive 1 (of 1)."
  29. # Contents:  Makefile README README.v1 name.c names.csh names.sh
  30. # Wrapped by slocum@merlin on Tue Nov  7 18:14:20 1989
  31. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  32. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  33.   echo shar: Will not clobber existing file \"'Makefile'\"
  34. else
  35. echo shar: Extracting \"'Makefile'\" \(476 characters\)
  36. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  37. X#  makefile for name.c
  38. X#
  39. X#       Comment out the BSD line if you're on System V
  40. X#       Comment out the SYSV line if you're using Berkely Unix.
  41. X#       Comment out both lines if you're using Microsoft C with MS-DOS.
  42. X#
  43. X#       Uncomment the DIST = -DSCRABBLE line, if you want to use the
  44. X#       Scrabble (tm) distribution of letters.
  45. X
  46. X# SYSTEM = -DSYSV 
  47. XSYSTEM = -DBSD
  48. X
  49. XDIST = -DSCRABBLE
  50. X#DIST = 
  51. XCFLAGS = -O $(SYSTEM) $(DIST)
  52. Xname:   name.c
  53. X    cc -o name $(CFLAGS) name.c
  54. X
  55. END_OF_FILE
  56. if test 476 -ne `wc -c <'Makefile'`; then
  57.     echo shar: \"'Makefile'\" unpacked with wrong size!
  58. fi
  59. chmod +x 'Makefile'
  60. # end of 'Makefile'
  61. fi
  62. if test -f 'README' -a "${1}" != "-c" ; then 
  63.   echo shar: Will not clobber existing file \"'README'\"
  64. else
  65. echo shar: Extracting \"'README'\" \(525 characters\)
  66. sed "s/^X//" >'README' <<'END_OF_FILE'
  67. XThis is version 3.0 of my rndname program. The major addition
  68. Xto this program is the inclusion of the Scrabble (tm) letter
  69. Xdistribution, as well as the previous flat distribution.
  70. XBy adding the -DSCRABBLE switch in the Makefile, the program
  71. Xis generated with these distributions.
  72. X
  73. XPlease send me any comments or modifications you have.
  74. X---
  75. XBrett Slocum, Honeywell SSDC, Golden Valley, Minnesota
  76. X<uunet!hi-csc!slocum>              | AIDS is a virus; George Bush
  77. X  or <hi-csc!slocum@uunet.uu.net>  | is a punishment from God.
  78. X
  79. END_OF_FILE
  80. if test 525 -ne `wc -c <'README'`; then
  81.     echo shar: \"'README'\" unpacked with wrong size!
  82. fi
  83. chmod +x 'README'
  84. # end of 'README'
  85. fi
  86. if test -f 'README.v1' -a "${1}" != "-c" ; then 
  87.   echo shar: Will not clobber existing file \"'README.v1'\"
  88. else
  89. echo shar: Extracting \"'README.v1'\" \(1157 characters\)
  90. sed "s/^X//" >'README.v1' <<'END_OF_FILE'
  91. XThis program is a very simple random name generator for use
  92. Xwith roleplaying games.  It produces surprisingly good names
  93. Xfor the very simple method used.  The names tend to be exotic, 
  94. Xsince 'X' and  'Z' have the same chance of coming up as 'T' and 
  95. X'N'.  Many of the names have a Japanese or African flavor.  Some 
  96. Xof my favorites came in the first page generated: Zozaras, Lyxam, 
  97. XRux, and Zelica.  
  98. X
  99. XThe program 'name.c' produces the names, and two scripts are 
  100. Xincluded to formats them into pages: names.csh and names.sh, 
  101. Xfor C-shell and Bourne shell, respectively.  Instructions for 
  102. Xchanging the distribution of letters are given in comments in 
  103. Xname.c.
  104. X
  105. XThese programs have been tested on an Apollo DN330 with both
  106. XBSD4.2 and Sys V, and on BSD4.3.  The makefile and names.csh 
  107. Xscript have Sys V versions commented out.  The changes for
  108. XMS-DOS similar to the ones used here have been tested, but
  109. Xthe specific changes for MS-DOS in this program have not.
  110. X
  111. XSend any changes or updates to me:
  112. X
  113. XBrett Slocum   UUCP: ...uunet!hi-csc!slocum
  114. X               Arpa: hi-csc!slocum@uunet.uu.net
  115. X"My name is Inigo Montoya. You killed my father. Prepare to die."
  116. X
  117. END_OF_FILE
  118. if test 1157 -ne `wc -c <'README.v1'`; then
  119.     echo shar: \"'README.v1'\" unpacked with wrong size!
  120. fi
  121. chmod +x 'README.v1'
  122. # end of 'README.v1'
  123. fi
  124. if test -f 'name.c' -a "${1}" != "-c" ; then 
  125.   echo shar: Will not clobber existing file \"'name.c'\"
  126. else
  127. echo shar: Extracting \"'name.c'\" \(4189 characters\)
  128. sed "s/^X//" >'name.c' <<'END_OF_FILE'
  129. X/**************************************************************************
  130. X *      name - prints random names                                        * 
  131. X *  Copyright 1988, 1989 by Brett Slocum.  All rights reserved.           *
  132. X *  Permission is granted to distribute, modify, or use portions of this  *
  133. X *  code in other programs, as long as this notice remains intact.        *
  134. X *  This program or its derivatives may not be sold for profit without    *
  135. X *  permission.                                                           *
  136. X *                                                                        *
  137. X *  UNIX  Version: Brett Slocum UUCP: ...uunet!hi-csc!slocum              *
  138. X *                              ARPA: slocum@hi-csc.honeywell.com         *
  139. X *  Changes were suggested by Geoff Kimbrough <geoff@ism780c.isc.com>     *
  140. X *                                                                        *
  141. X *  IBM Microsoft C v5.0 changes by Loyd Blankenship on 11-15-88          *
  142. X *                            UUCP: ...rutgers.edu!cs.utexas.edu!nth!loyd *
  143. X *                                                                        *
  144. X *  Version 2 by Brett Slocum 3/22/89 : various cleanups, features, etc.  *
  145. X *                                                                        *
  146. X *  Version 3 by Brett Slocum 11/7/89 : Scrabble (tm) letter distribution *
  147. X *                                                                        *
  148. X **************************************************************************/
  149. X
  150. X#ifdef SYSV
  151. X#include <string.h>
  152. X#define srandom srand48
  153. X#define random lrand48
  154. X#endif
  155. X
  156. X#ifdef BSD
  157. X#include <strings.h>
  158. X#endif
  159. X
  160. X#ifdef MSC
  161. X#include <string.h>
  162. X#include <stdio.h>
  163. X#include <stdlib.h>
  164. X#include <time.h>
  165. X#define srandom srand
  166. X#define random rand
  167. X#endif
  168. X
  169. X#include <ctype.h>
  170. X
  171. X#define YES 1
  172. X#define NO 0
  173. X#define MAXNAME 30
  174. X#define MINLENGTH 3
  175. X#define RANGE 6
  176. X#define rnd(n) (unsigned)(random() % (n))
  177. X
  178. X/*
  179. X   Since "y" appears twice, once in each string; all other 
  180. X   letters, except "'", are doubled to keep the distribution even.
  181. X   By adding or deleting the letters from these strings, you
  182. X   can change the frequency of appearance of the letters,
  183. X   (i.e. by adding an "e" and a "t" and deleting a "z" and a "q",
  184. X   a distribution closer to English could be made.)
  185. X
  186. X   Another set of strings has the Scrabble (tm) distributions of letters.
  187. X   Put -DSCRABBLE into the Makefile, if you want the Scrabble (tm) distribution.
  188. X*/
  189. X
  190. X#define FLAT_VOWELS "aaeeiioouuy'"
  191. X#define FLAT_CONS "bbccddffgghhjjkkllmmnnppqqrrssttvvwwxxyzz'"
  192. X#define SCRABBLE_VOWELS "aaaaaaaaaeeeeeeeeeeeeiiiiiiiiioooooooouuuuy'"
  193. X#define SCRABBLE_CONS "bbccddddffggghhjkllllmmnnnnnnppqrrrrrrssssttttttvvwwxyz'"
  194. X
  195. X#ifdef SCRABBLE
  196. Xchar vowels[] = SCRABBLE_VOWELS;
  197. Xchar cons[] = SCRABBLE_CONS;
  198. X#else
  199. Xchar vowels[] = FLAT_VOWELS;
  200. Xchar cons[] = FLAT_CONS;
  201. X#endif
  202. X
  203. Xmain(argc, argv)  
  204. Xint argc;
  205. Xchar *argv[];
  206. X{
  207. X     int n, letters, vowel;
  208. X     char name[MAXNAME];
  209. X
  210. X     if (argc == 2) {
  211. X         /* initialize random number generator */
  212. X         srandom(time(0L));
  213. X         
  214. X         /* generate argv[1] names */
  215. X         for (n = atoi(argv[1]); n > 0; n--) {
  216. X             name[0] = '\0';
  217. X             /* choose whether first character is a vowel */
  218. X             vowel =  (rnd(2) ? YES : NO);
  219. X             /* get initial character - not " ' " */
  220. X             if (vowel)  
  221. X                 strncat(name, &vowels[rnd(sizeof(vowels) - 2)], 1);
  222. X             else 
  223. X                 strncat(name, &cons[rnd(sizeof(cons) - 2)], 1);
  224. X             /* upper case first letter */
  225. X             name[0] = _toupper(name[0]);
  226. X             /* complete rest of letters */
  227. X             for (letters = rnd(RANGE) + MINLENGTH; letters > 0; letters--) {
  228. X                 /* alternate vowels and consonants */
  229. X                 vowel = ( vowel ? NO : YES );
  230. X                 /* get next character */
  231. X                 if (vowel) 
  232. X                     strncat(name, &vowels[rnd(sizeof(vowels)-1)], 1);
  233. X                 else 
  234. X                     strncat(name, &cons[rnd(sizeof(cons)-1)], 1);
  235. X             }
  236. X             printf("%s\n", name);
  237. X         }
  238. X     }
  239. X     else 
  240. X         printf("Usage: name number-of-names\n");
  241. X}
  242. X
  243. END_OF_FILE
  244. if test 4189 -ne `wc -c <'name.c'`; then
  245.     echo shar: \"'name.c'\" unpacked with wrong size!
  246. fi
  247. chmod +x 'name.c'
  248. # end of 'name.c'
  249. fi
  250. if test -f 'names.csh' -a "${1}" != "-c" ; then 
  251.   echo shar: Will not clobber existing file \"'names.csh'\"
  252. else
  253. echo shar: Extracting \"'names.csh'\" \(398 characters\)
  254. sed "s/^X//" >'names.csh' <<'END_OF_FILE'
  255. X#! /bin/csh
  256. X# names - generate random names
  257. X#
  258. X# usage: names [pages]
  259. X# where 'pages' is how many pages of names you want.  Default = 1 page.
  260. X
  261. Xif ($#argv == 0) then
  262. X    @ n = 336
  263. Xelse 
  264. X    @ n = 336 * $1
  265. Xendif
  266. X
  267. X# BSD script -- uncomment this line if BSD
  268. Xname $n | sort -u | pr -6 | expand
  269. X
  270. X# sysv script -- uncomment this line if SYSV
  271. X# note: no tab expansion performed
  272. X
  273. X#name $n | sort -u | pr -6
  274. X
  275. END_OF_FILE
  276. if test 398 -ne `wc -c <'names.csh'`; then
  277.     echo shar: \"'names.csh'\" unpacked with wrong size!
  278. fi
  279. chmod +x 'names.csh'
  280. # end of 'names.csh'
  281. fi
  282. if test -f 'names.sh' -a "${1}" != "-c" ; then 
  283.   echo shar: Will not clobber existing file \"'names.sh'\"
  284. else
  285. echo shar: Extracting \"'names.sh'\" \(94 characters\)
  286. sed "s/^X//" >'names.sh' <<'END_OF_FILE'
  287. Xif [ $# = 0 ]
  288. Xthen
  289. X    n=`expr 336`
  290. Xelse
  291. X    n=`expr 336 \* $1`
  292. Xfi
  293. Xname $n | sort -u | pr -6
  294. X
  295. END_OF_FILE
  296. if test 94 -ne `wc -c <'names.sh'`; then
  297.     echo shar: \"'names.sh'\" unpacked with wrong size!
  298. fi
  299. chmod +x 'names.sh'
  300. # end of 'names.sh'
  301. fi
  302. echo shar: End of archive 1 \(of 1\).
  303. cp /dev/null ark1isdone
  304. MISSING=""
  305. for I in 1 ; do
  306.     if test ! -f ark${I}isdone ; then
  307.     MISSING="${MISSING} ${I}"
  308.     fi
  309. done
  310. if test "${MISSING}" = "" ; then
  311.     echo You have the archive.
  312.     rm -f ark[1-9]isdone
  313. else
  314.     echo You still need to unpack the following archives:
  315.     echo "        " ${MISSING}
  316. fi
  317. ##  End of shell archive.
  318. exit 0
  319.  
  320. -- 
  321. Brett Slocum <uunet!hi-csc!slocum>
  322.     or <hi-csc!slocum@uunet.uu.net>
  323.  
  324. There is something fascinating about science.  One gets such wholesale
  325. returns of conjecture out of such a trifling investment of fact.
  326.         -- Mark Twain
  327.  
  328.